import { useRef } from 'react';

import { InputNumber, InputNumberProps } from 'antd';

type BizObamountct = BIZAPI.ProDataRevenueYearEntity;
const NumberInput = (
  props: InputNumberProps & {
    edit?: boolean;
    onChange?: (val: number) => void;
    record?: any;
    table: any;
    name?: any;
  }
) => {
  const inputRef = useRef<HTMLInputElement>(null);
  const blurEdit = useRef(true);
  return (
    <div>
      {props.edit ? (
        <InputNumber
          ref={inputRef}
          min={0}
          max={1000000000}
          precision={3}
          style={{ width: '100%' }}
          value={props.value}
          step={0.001}
          onChange={(value) => {
            props.onChange?.(value);
          }}
          onBlur={() => {
            blurEdit.current = false;
            // props.table?.refresh();
            // props.table.updateRow(props.record);
          }}
          {...props}
        />
      ) : (
        <div
          style={{ cursor: 'pointer', height: '34px' }}
          onClick={() => {
            // props.table?.refresh();

            console.log('props.value:', props.value);
            setTimeout(() => {
              inputRef.current?.focus();
            }, 50);
          }}
        >
          {props.value == 0 ? '' : props.value}
        </div>
      )}
    </div>
  );
};

export default NumberInput;
